const router = require('koa-router')();
const ejs = require('ejs');
const path = require('path');


router.get('/:id', async (ctx) => {
  const viewPath = path.resolve(__dirname, `../view/article/${ctx.params.id}.ejs`);
  const str = await new Promise((resolve, reject) => {
    ejs.renderFile(viewPath, {}, {
      cache: true,
      filename: templatePath,
    }, function(err, str){
      if(err) {
        reject(err)
      } else {
        // str => 输出渲染后的 HTML 字符串
        resolve(str)
      }
    });
  });
  ctx.type = 'text/html';
  ctx.body = str;
});

// router.get('(.*)', async (ctx) => {
//   ctx.type = 'text/html';
//   ctx.body = '2222222';
// });

module.exports = router;
